package org.lql.algo.codecrush.week007;

/**
 * @author: liangqinglong
 * @date: 2025-08-18 13:45
 * @description: 367. 有效的完全平方数 <a href="https://leetcode.cn/problems/valid-perfect-square/description/">...</a>
 **/
public class IsPerfectSquare {

	public boolean isPerfectSquare(int num) {
		int left = 0;
		int right = num;
		while (left < right) {
			int mid = left + (right - left) / 2;
			if (mid * mid == num) {
				return true;
			} else if (mid * mid > num) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		return left * left == num;
	}

	public static void main(String[] args) {
		IsPerfectSquare isPerfectSquare = new IsPerfectSquare();
		System.out.println(isPerfectSquare.isPerfectSquare(16));
		System.out.println(isPerfectSquare.isPerfectSquare(14));
	}
}
